using System;
using System.Collections;

namespace SystemFrameworks.Util
{
	/// <summary>
	/// Summary description for ConvertErrMessage.
	/// </summary>
	public class ConvertErrMessage
	{
		private const string CTLF  = "<br>&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;";
		private const string CTLF_HEAD  = "&nbsp;&nbsp;&nbsp;&nbsp-&nbsp;&nbsp;";
		private const string CTLF_NOHEAD = "&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;";
		private const string CTLF_NOPRE  = "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

		/// <summary>
		/// Construction function
		/// </summary>
		public ConvertErrMessage()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		/// <summary>
		/// Convert the arrayList collections to a string
		/// </summary>
		/// <param name="arrLstErr">Error message list</param>
		/// <returns>Converted error message </returns>
		public static string converter(ArrayList arrLstErr )
		{																	
			return getListMsg(arrLstErr, true);			
		}

		/// <summary>
		///  convert a error string to a formated string
		/// </summary>
		/// <param name="sMessageErr">Error message</param>
		/// <returns>Converted error message </returns>
		public static string  converter(string sMessageErr)
		{
			if(null!=sMessageErr && sMessageErr.Trim().Length>0)
			{
				sMessageErr = CTLF_HEAD + sMessageErr;
			}
			return sMessageErr;
		}

		/// <summary>
		/// Compose the error message string from the arraylist 
		/// </summary>
		/// <param name="lstErr">Error message list</param>
		/// <param name="bAddPre">Flag to add the prefix</param>
		/// <returns>Converted error message </returns>
		private static string getListMsg(ArrayList lstErr , bool bAddPre)
		{
			string strMsg = CTLF_HEAD;
			int shCnt  = 0;
			string sData = "";

			if(bAddPre==true)
			{
				strMsg=CTLF_HEAD;
			}
			else
			{
				strMsg = CTLF_NOHEAD;
			}
			IEnumerator iEnum   = lstErr.GetEnumerator();
			while( iEnum.MoveNext() )
			{
				sData = (string)iEnum.Current;
				if( sData.Trim().Length > 0)
				{
					shCnt = shCnt + 1;
				}
				if(shCnt==1)
				{
					strMsg += sData;
				}
				else
				{
					if(bAddPre==true)
					{
						strMsg = strMsg + CTLF + sData;
					}
					else
					{
						strMsg = strMsg + CTLF_NOPRE + sData;
					}
				}
			}
			return strMsg;
		}
	}
}




																															